import 'package:flutter/material.dart';
import 'package:flutter_yfree/YFree.dart';
import 'package:pc/Util/FileUtils.dart';
import 'package:screen_capturer/screen_capturer.dart';

class ChatScreenshotButton extends StatefulWidget {
  const ChatScreenshotButton({
    required this.onCapture,
    Key? key,
  }) : super(key: key);

  final Function(String? file) onCapture;

  @override
  _ChatScreenshotButtonState createState() => _ChatScreenshotButtonState();
}

class _ChatScreenshotButtonState extends State<ChatScreenshotButton> {
  bool isShowPopup = false;

  @override
  Widget build(BuildContext context) {
    return YButton(
      isInk: true,
      child: Icon(Icons.cut_rounded, color: Colors.grey.shade600, size: 20),
      onTap: () async {
        CapturedData? capturedData = await ScreenCapturer.instance.capture(
          mode: CaptureMode.region, // screen, window
          imagePath: "${await FileUtils.getDir(FileDir.cache_image)}/cap_${DateTime.now().microsecondsSinceEpoch}.png",
        );
        if (capturedData?.imagePath == null) return;
        widget.onCapture(capturedData?.imagePath);
      },
    );
  }
}
